﻿@model KL.Store.Web.Models.CriticalStockModel
@{
    Layout = null;

    var pageToPrev = 1;
    var pageToNext = Model.PageCount;
    if (Model.Page > 7)
    {
        pageToPrev = Model.Page - 7;
    }
    if ((Model.Page + 7) < Model.PageCount)
    {
        pageToNext = Model.Page + 7;
    }
    var firstPageClass = "";
    if (Model.Page == 1)
    {
        firstPageClass = " class=\"disabled\"";
    }
    var lastPageClass = "";
    if (Model.Page == Model.PageCount)
    {
        lastPageClass = " class=\"disabled\"";
    }
}
@if (!string.IsNullOrEmpty(ViewBag.PageUrl))
{
    <ul class="sidepagination left">
        <li>
            <select name="AmbarList" class="form-control">
                <option value="0">Tümü</option>
                @foreach (var ambar in Model.AmbarList)
                {
                    <option value="@ambar.IdAmbar" @{if (Model.AmbarId == ambar.IdAmbar)
                                                     {<text> selected="selected"</text>}}>@ambar.AmbarAdi</option>
                }
            </select>
        </li>
        <li>
            <a href="/ReportPanel/ExportCriticalStocks?AmbarId=@(Model.AmbarId)" class="btn btn-info"><i class="glyphicon glyphicon-save"></i>&nbsp;Excel Export</a>
        </li>
    </ul>   
}
@if (Model.PageCount > 1)
{
    <ul class="pagination right">
        <li@(firstPageClass)><a href="@(ViewBag.PageUrl)?AmbarId=@(Model.AmbarId)&Page=1">&laquo;</a></li>
        @for (var i = pageToPrev; i <= pageToNext; i++)
        {
            <li@{ if (Model.Page == i)
                  { <text> class="active"</text>} }><a href="@(ViewBag.PageUrl)?AmbarId=@(Model.AmbarId)&Page=@(i)">@(i)</a></li>
        }
        <li@(lastPageClass)><a href="@(ViewBag.PageUrl)?AmbarId=@(Model.AmbarId)&Page=@(Model.PageCount)">&raquo;</a></li>
    </ul>
}
<div class="clearfix"></div>
@if (!string.IsNullOrEmpty(ViewBag.PageUrl))
{
    <div class="col-xs-12 hidden-md hidden-lg  first last"><span class="hidden-md hidden-lg right"><a href="javascript:void(0);" class="sectionOC" onclick="expandSection('#LastCriticalStocksPlaceHolder');">Genişlet/Daralt&nbsp;<i class="fa fa-bars"></i></a></span></div>
}
<table class="table table-bordered">
    <thead>
        <tr>
            <td class="hideOnMobile">Barkod</td>
            <td>Stok Adı</td>
            <td>Kalan Miktar</td>
            <td>Şube</td>
        </tr>
    </thead>
    <tbody>
        @foreach (var stock in Model.StockList)
        {
            <tr>
                <td class="hideOnMobile">@stock.Barkod</td>
                <td><a href="@stock.LinkUrl" target="_blank">@stock.StokAdi</a></td>
                <td>@stock.StokMiktari.ToString("###,###,##0")</td>
                <td>@stock.AmbarAdi</td>
            </tr>
        }
    </tbody>
</table>
@if (Model.PageCount > 1)
{
    <ul class="pagination right">
        <li@(firstPageClass)><a href="@(ViewBag.PageUrl)?AmbarId=@(Model.AmbarId)&Page=1">&laquo;</a></li>
        @for (var i = pageToPrev; i <= pageToNext; i++)
        {
            <li@{ if (Model.Page == i)
                  { <text> class="active"</text>} }><a href="@(ViewBag.PageUrl)?AmbarId=@(Model.AmbarId)&Page=@(i)">@(i)</a></li>
        }
        <li@(lastPageClass)><a href="@(ViewBag.PageUrl)?AmbarId=@(Model.AmbarId)&Page=@(Model.PageCount)">&raquo;</a></li>
    </ul>
    <div class="clearfix"></div>
}
<script>
    $("select[name=AmbarList]").change(function ()
    {
        var selectedValue = $(this).find(':selected').val();
        window.location.href = '@(ViewBag.PageUrl)?AmbarId=' + selectedValue;
    });

    @* function AmbarSec(AmbarId)
    {
        window.location.href = '@(ViewBag.PageUrl)?AmbarId=' + AmbarId;
    }*@
</script>
